home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.013.Math / math.init.aii < prev    next >
Encoding:
Text File  |  1990-06-24  |  8.0 KB  |  384 lines  |  [TEXT/MPS ]

  1. *******************************************************************************
  2. * StandardLib.Aii
  3. *
  4. * (C)  Copyright Apple Computer, Inc. 1988-1990
  5. * All rights reserved.
  6. *
  7. * Developer Technical Support Apple II Sample Code
  8. *
  9. * by Jim Mensch & Keith Rollin
  10. *
  11. * This file contains standard routines used by all the applications on the DTS
  12. * Demo Disk. This file relies on certain data structures being available in a GLOBALS
  13. * data record in the main file.
  14. *
  15. *******************************************************************************
  16.     PRINT PUSH,OFF
  17.  
  18.     EJECT
  19. *******************************************************************************
  20. *
  21. InitTools    PROC
  22. *
  23. * Description:    Load and initialize the tools needed. Errors are detected
  24. *    and FatalError is called if any occur. If there aren't any
  25. *    errors, the list of menu templates is read and the menu-
  26. *    bar is created.
  27. *
  28. *
  29. * Inputs:    NONE
  30. *
  31. * Outputs:    NONE
  32. *
  33. * External Refs:
  34.     import FatalError
  35. *
  36. * Entry Points:    NONE
  37. *
  38. *******************************************************************************
  39.     with Globals
  40.  
  41. ;
  42. ;   Tool Direct page offsets here
  43. ;
  44. QDDPage    equ $0000
  45. EMDPage    equ QDDPage+$0300
  46. CtlDPage    equ EMDPage+$0100
  47. MenuDPage    equ CtlDPage+$0100
  48. LEDPage    equ MenuDPage+$0100
  49. SaneDPage    equ LEDPage+$0100
  50. ToolDPSize    equ SaneDPage+$0100
  51.  
  52.     phk    ; Save program bank register and
  53.     plb    ; load it as the data bank register
  54.  
  55.     tdc
  56.     sta MyDP    ; Save direct register
  57.  
  58.     _TLStartUp    ; Start Tool Locator
  59.  
  60.     pha    ; Space for result
  61.     _MMStartUp    ; Start memory manager
  62.     PullWord MyID    ; Save it for later use
  63.  
  64.     _MTStartUp    ; Start up Misc Tools
  65.  
  66.     _IMStartUp    ; Start integer math toolset
  67.  
  68.     PushLong #ToolTable    ; Pointer to Tool table
  69.     _LoadTools    ; Load all RAM based tools
  70.     bcc IT0005    ; Carry clear means no error
  71.     brl FatalError    ; Tools can't be loaded. Fatal error!
  72.  
  73. IT0005
  74.  
  75. ; Get memory for Tool Direct pages
  76.  
  77.     pha    ; Room for result
  78.     pha
  79.     PushLong #ToolDPSize; Number of bytes needed
  80.     PushWord MyID    ; ID of this application
  81.     PushWord #attrLocked+attrFixed+attrPage+attrBank
  82.     PushLong #0    ; Allocate them in bank 0
  83.     _NewHandle
  84.     bcc IT0010    ; Test carry for error
  85.     brl FatalError    ; If no memory we got a fatal error!
  86.  
  87. IT0010    PullLong DPHandle    ; Retrieve handle to our DPage area
  88.  
  89.     lda [DPHandle]    ; Dereference the handle to get a ptr
  90.     sta DPPointer    ; to our direct page area and save it.
  91.  
  92.     PushWord DPPointer    ; QuickDraw uses 3 pages of Dpage
  93.     PushWord #ScreenMode; Used to set all master SCB's
  94.     PushWord #0    ; Zero means use default buf size
  95.     PushWord MyID    ; Application ID for allocating data
  96.     _QDStartUp    ; Start QuickDraw, turn on SHR Screen
  97.     bcc IT0015
  98.     brl FatalError    ; If it can't be started then bomb
  99.  
  100. IT0015    _QDAuxStartUp    ; No error possible for this call
  101.  
  102.     lda DPPointer    ; Create address for Event Mgr DPage by
  103.     clc    ; loading in the pointer to the start
  104.     adc #EMDPage    ; of DPage and adding Evt Mgr offset.
  105.     pha    ; Now push it on the stack.
  106.     PushWord #20    ; Size of event queue.
  107.     PushWord #0    ; MouseClamp values.
  108.     PushWord #ScreenWidth ; These will clamp mouse to screen
  109.     PushWord #0    ; area only.
  110.     PushWord #200
  111.     PushWord MyID
  112.     _EMStartUp    ; Start the event manager
  113.     bcc IT0020
  114.     brl FatalError    ; Event manager is also a must
  115. IT0020
  116.     PushWord MyID
  117.     _WindStartUp
  118.     bcc IT0025
  119.     brl FatalError
  120. IT0025
  121.     PushWord MyID
  122.     lda DPPointer
  123.     clc
  124.     adc #CtlDPage
  125.     pha
  126.     _CtlStartUp
  127.     bcc IT0030
  128.     brl FatalError
  129. IT0030
  130.  
  131.     PushWord MyID
  132.     lda DPPointer
  133.     clc
  134.     adc #MenuDPage
  135.     pha
  136.     _MenuStartUp
  137.     bcc IT0035
  138.     brl FatalError
  139. IT0035
  140.     PushWord MyID
  141.     lda DPPointer
  142.     clc
  143.     adc #LEDPage
  144.     pha
  145.     _LEStartUp
  146.     bcc IT0040
  147.     brl FatalError
  148. IT0040
  149.     PushWord MyID
  150.     _DialogStartUp
  151.     bcc IT0045
  152.     brl FatalError
  153. IT0045
  154.  
  155.     lda DPPointer
  156.     clc
  157.     adc #SaneDPage
  158.     pha
  159.     _SANEStartUp
  160.             
  161.  
  162.     _ListStartUp
  163.  
  164.     _ScrapStartUp    ; No error possible for this call
  165.  
  166.     _DeskStartUp    ; No error possible for this call
  167.  
  168.     PushLong #0
  169.     _RefreshDeskTop
  170.  
  171. ;
  172. ; Create the menus I need
  173. ;
  174.  
  175.     ldx #MenuPtrLen-4    ; Get a pointer to the last menu    
  176. loop    phx    ; Save menu table index on the stack
  177.     pha    ; Push on space for the menu handle
  178.     pha    ;   returned by NewMenu
  179.     lda MenuPtr+2,x    ; Push on the pointer to the template
  180.     pha    ;   to be used by NewMenu when
  181.     lda MenuPtr,x    ;   creating the menu
  182.     pha
  183.     _NewMenu    ; Create a new menu
  184.     PushWord #0    ; Tell InsertMenu where to put it
  185.     _InsertMenu    ; Insert it.
  186.     plx    ; Get our index back off the stack
  187.     dex    ; Point to the next template pointer
  188.     dex
  189.     dex
  190.     dex
  191.     bpl loop    ; Go back up if not done yet.
  192.  
  193.     PushWord #1    ; Add NDA's
  194.     _FixAppleMenu
  195.  
  196.     pha    ; Now call CalcMenuSize for all menus
  197.     _FixMenuBar
  198.     PullWord MenuHeight
  199.  
  200.     _DrawMenuBar    ; Finally, draw it.
  201.  
  202.     RTS
  203.  
  204. ToolTable    dc.W 8    ; Data Block for LoadTools call
  205.     dc.W 14,$0100    ; Window Manager
  206.     dc.W 15,$0100    ; Menu Manager
  207.     dc.W 16,$0100    ; Control Manager
  208.     dc.W 18,$0100    ; QD Aux
  209.     dc.W 20,$0100    ; LineEdit tool set
  210.     dc.W 21,$0100    ; Dialog Manager
  211.     dc.W 22,$0100    ; Scrap manager
  212.     dc.W 28,$0100    ; List Manager
  213.  
  214.     ENDP
  215.  
  216.     EJECT
  217. *******************************************************************************
  218. *
  219. FatalError    PROC
  220. *
  221. * Description:    Routine that is called whenever a tool sends back an error
  222. *    that can not be recovered from. This routine prints the
  223. *    error on the screen, waits for a keypress then quits back
  224. *    to whoever started this application up!
  225. *
  226. *
  227. * Inputs:    A = Error number
  228. *
  229. * Outputs:    NONE (program exits)
  230. *
  231. * External Refs:
  232.     import CloseTools
  233. *
  234. * Entry Points:    NONE
  235. *
  236. *******************************************************************************
  237.     with Globals
  238.  
  239.     pha    ; Push the error code
  240.     PushLong #ErrNumStr    ; Address of storage area
  241.     PushWord #4    ; Length of string
  242.     _Int2Hex
  243.  
  244.     _GrafOff    ; If QD Started, shut off graphics
  245.  
  246.     PushLong #ErrStr    ; Write error message to the screen
  247.     _WriteCString
  248.  
  249.     pha    ; Space for result
  250.     PushWord #0    ; No echo
  251.     _ReadChar    ; Wait for a key to be pressed
  252.     pla    ; Discard the key
  253.  
  254.     jsr CloseTools    ; Shut down all the tools in case
  255. ;          any got started up
  256.  
  257.     _Quit QuitParms    ; Quit back to where we came from.
  258.  
  259.     brk $FF    ; If the quit fails then just break
  260.     
  261. ErrStr    dc.B 'A fatal error has occured $'
  262. ErrNumStr    dc.B 'xxxx   press any key to exit',0
  263.  
  264.     ENDP
  265.  
  266.     EJECT
  267. *******************************************************************************
  268. *
  269. CloseTools    PROC
  270. *
  271. * Description:    Shut down the tools I started.
  272. *
  273. *
  274. * Inputs:    NONE
  275. *
  276. * Outputs:    NONE
  277. *
  278. * External Refs:    NONE
  279. *
  280. * Entry Points:    NONE
  281. *
  282. *******************************************************************************
  283.     with Globals
  284.  
  285.     _DeskShutDown
  286.     _ScrapShutDown
  287.     _SANEShutDown
  288.     _ListShutdown
  289.     _DialogShutDown
  290.     _LEShutDown
  291.     _MenuShutDown
  292.     _CtlShutDown
  293.     _WindShutDown
  294.     _EMShutDown
  295.     _QDAuxShutDown
  296.     _QDShutDown
  297.     _MTShutDown
  298.  
  299.     PushLong DPHandle    ; Dispose of all that DP memory
  300.     _DisposeHandle
  301.  
  302.     PushWord MyID
  303.     _MMShutDown
  304.     _TLShutDown
  305.  
  306.     rts
  307.     ENDP
  308.  
  309.     EJECT
  310. *******************************************************************************
  311. *
  312. doAbout    PROC
  313. *
  314. * Description:    Bring up an Alert Dialog box with our name in it.
  315. *
  316. * Inputs:    NONE
  317. *
  318. * Outputs:    NONE
  319. *
  320. * External Refs:    NONE
  321. *
  322. * Entry Points:    NONE
  323. *
  324. *******************************************************************************
  325.     With Globals
  326.  
  327.     pha    ; space for result
  328.     PushLong #AboutBox    ; pointer to alert template
  329.     PushLong #0    ; pointer to a filter proc (0=none)
  330.     _NoteAlert
  331.     pla    ; get the item hit and dispose
  332.  
  333.     rts
  334.  
  335. ; About Box alert template
  336.  
  337. AboutBox    dc.W 30,30,100,590    ; for 320 use 30,30,100,290
  338.     dc.W 1    ; this is alert # 1
  339.     dc.B $80    ; draw for this stage
  340.     dc.B $81    ; draw for this stage
  341.     dc.B $82    ; draw for this stage
  342.     dc.B $83    ; draw for this stage
  343.     dc.L OKButton    ; ok button for the    alert
  344.     dc.L AboutTitle    ; title of the program
  345.     dc.L AboutAut    ; author
  346.     dc.L AboutVers    ; version number string
  347.     dc.L 0    ; nil to end the list
  348.  
  349. OKBTitle    dc.B 2,'OK'
  350. OKButton    dc.W 1
  351.     dc.W 50,500,65,550
  352.     dc.W buttonItem
  353.     dc.L OKBTitle
  354.     dc.W 0
  355.     dc.W 0    ; item flag
  356.     dc.L 0    ; no color table
  357.  
  358. AboutTitle    dc.W 2
  359.     dc.W 10,100,20,550
  360.     dc.W statText+itemDisable
  361.     dc.L TitleString
  362.     dc.W 0
  363.     dc.W 0    ; item flag
  364.     dc.L 0    ; no color table
  365.  
  366. AboutAut    dc.W 3
  367.     dc.W 25,100,35,550
  368.     dc.W statText+itemDisable
  369.     dc.L AutString
  370.     dc.W 0
  371.     dc.W 0    ; item flag
  372.     dc.L 0    ; no color table
  373.  
  374. AboutVers    dc.W 4
  375.     dc.W 40,100,50,550
  376.     dc.W statText+itemDisable
  377.     dc.L VersString
  378.     dc.W 0
  379.     dc.W 0    ; item flag
  380.     dc.L 0    ; no color table
  381.  
  382.     ENDP
  383.  
  384.     PRINT POP